// 1.引入mongoose模块
const mongoose = require('mongoose');

// 2.创建文章集合规则
const articleSchema = new mongoose.Schema({
	title: {
		type: String,
		maxlength: 20,
		minlength: 4,
		required: [true, '请填写文章标题']
	},
	publishDate: {
		type: Date,
		default: Date.now
	},
    updateDate:{
        type: Date,
		default: Date.now
    },
	cover: {
		type: String,
		default: null
	},
	content: {
		type: String,
        default:'null'
	},
    words:{
        type:String,
        require:[true,'文章字数不能为空']
    },
    readtime:{
        type:'String',
        require:[true,'阅读时间不能为空']
    },
	status:{
		type:Boolean,
		default:true
	},
	about:{
		type:String,
		require:[true,'简介不能为空']
	},
	class:{
			type: mongoose.Schema.Types.ObjectId,
			ref: 'Classify',
			default:'61da9432b9230e04e9aad81b'
	},
	label:{
		type:Array,
		default:[]
	},
})


// 3.根据规则创建集合
const Article = mongoose.model('Article', articleSchema);


// 4.将集合做为模块成员进行导出
module.exports = {
	Article
}